import java.util.List;


public class CPU implements Runnable {
	
	
	private Thread my_thread;
	
	/**
	 * The instruction address where the cpu is currently at 
	 * for a process. (program counter)
	 */
	private int my_PC;  
	
	/**
	 * List of the Process control blocks 
	 */
	private List<Pcb> my_PCB_List;
	
	/**
	 * Current Process Control BLock of the running process
	 */
	private Pcb my_PCB;
	
	/**
	 * Current running process 
	 */
	private Process my_process;
	
	 /**
     * Reference Shared Memory.
     */
    private Memory my_memory;

    /**
     * Reference to Scheduler.
     */
    private Scheduler my_scheduler;

	
	public CPU(List<Pcb> the_PCB_List, Scheduler the_scheduler, Memory the_Memory) {
		
		//my_thread = new Thread(this);
		
		my_PC = 0;
		my_memory = the_memory;
		my_scheduler = the_scheduler;
		my_PCB_List = the_PCB_List;
		
		my_PCB = my_PCB_List.get(0);
		my_process = my_PCB.getProc();
	}
	public void run() {
		//haven't used thread
		//maybe call my_thread.start() somewhere
		
		while(true) {
			
			my_PC++;
			my_PC = my_PC % my_process.getNoSteps();
			
			if(my_process.getReqList.contains(my_PC)) {
				saveState();
				break;
			}
		}
		
	}
	private void saveState() {
		//get type of process and find out which interrupt it is
		//need to do still
		my_PCB.setPC(my_PC);
		my_PCB.setState(/*1, 2, or 3*/); //interrupted, blocked, or ready 
									     //depending on what type of request
		//call routine depending on what kind of interrupt 
		
	}
	

}
